package com.neuedu.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.commons.text.WordUtils;

import java.sql.Types;

/**
 * 项目：mblog_java4
 * 创建时间：  2021-12-28   10:51
 * 作者 :jshand
 * 描述 : 字段
 */

@Data
@AllArgsConstructor
public class Column {

    private String labelName;

    private Integer columnType;
    private String columnTypeName;


    public String getJavaName() {
        String  name = WordUtils.capitalize(labelName,'_');
        name = name.replace("_","");

        //首字母变小写
        name = name.substring(0,1).toLowerCase()+name.substring(1);
        return name;
    }

    public String getJavaType(){
        switch (columnType){
            case Types.BIGINT:
            case Types.INTEGER:
            case Types.TINYINT:
            case Types.BIT:
                return "Integer";
            case Types.FLOAT:
            case Types.DOUBLE:
            case Types.DECIMAL:
                return "Double";
            case Types.VARCHAR:
            case Types.LONGVARCHAR:
            case Types.CHAR:
                return "String";
            case Types.DATE:
            case Types.TIME:
            case Types.TIMESTAMP:
                return "Date";
            default:
                return "未知类型:"+columnTypeName+",columnType:"+columnType;
        }
    }

    public String getResultType(){
        switch (columnType){
            case Types.BIGINT:
            case Types.INTEGER:
            case Types.TINYINT:
            case Types.BIT:
                return "Int";
            case Types.FLOAT:
            case Types.DOUBLE:
            case Types.DECIMAL:
                return "Double";
            case Types.VARCHAR:
            case Types.LONGVARCHAR:
            case Types.CHAR:
                return "String";
            case Types.DATE:
                return "Date";
            case Types.TIME:
                return "Time";
            case Types.TIMESTAMP:
                return "Timestamp";
            default:
                return "未知类型:"+columnTypeName+",columnType:"+columnType;
        }
    }

}
